﻿using UnityEngine;
using System.Collections;

public class HPBar : MonoBehaviour 
{
    public float hp = 18500;
    public float damage = 510;

    float totalhp;
    float healthPercent = 100;
    SpriteRenderer hpBar;
    Vector3 hpScale;

    void Start()
    {
        hpBar = GetComponent<SpriteRenderer>();
        hpScale = hpBar.transform.localScale;
        totalhp = hp;
    }

    void Update()
    {
        // Mouse left click 
        if (Input.GetMouseButtonDown(0))
        {
            hp -= damage;
            if (hp > 0)
                healthPercent = hp / totalhp;
            else
                healthPercent = 0;
            hpBar.transform.localScale = new Vector3(hpScale.x * healthPercent, 1, 1);
        }
    }
}
